﻿using System.Linq.Expressions;

using Tszy.Unlimited.Data.AdoNet.Sql.Components.Expressions.Where;

namespace Tszy.Unlimited.Data.AdoNet.Sql.Components.Expressions.Counts
{
    /// <summary>
    /// 实现 linq 中的 Any 函数。
    /// </summary>
    internal class AnyExpressionExecutor : ExpressionExecutorBase
    {
        private static readonly IExpressionExecutor _whereExpressionExecutor = new WhereExpressionExecutor();

        /// <summary>
        ///
        /// </summary>
        public AnyExpressionExecutor() : base(ExpressionKey.ANY)
        {
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public override ExpressionExecutorResult Execute(ExpressionContext context, Expression expression)
        {
            context.Any = true;

            if (expression != null)
                return _whereExpressionExecutor.Execute(context, expression);

            return ResultSuccess();
        }
    }
}